﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Configuration;

namespace WebsiteUI.ActionFilters
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple=false, Inherited=false)]
    public class CtrlActionOutputCacheAttribute : OutputCacheAttribute
    {
        public CtrlActionOutputCacheAttribute(string cacheProfile)
        {
            //asp.net mvc提供的OutputCache方法竟然有bug，读取CacheProfile会出错，所以才建了这个类来修复bug。
            //太坑爹了！！！！！！！
            var settings = (OutputCacheSettingsSection)WebConfigurationManager.GetSection("system.web/caching/outputCacheSettings");
            var profile = settings.OutputCacheProfiles[cacheProfile];
            Duration = profile.Duration;
            VaryByParam = profile.VaryByParam;
            VaryByCustom = profile.VaryByCustom;
        }
    }
}